package com.wheel.autoconfigure.drools;/*
 * <h3>Title:wheel-parent系统</h3>
 * <p>Copyright (c) 2021, wnfbx. All rights reserved.</p>
 * @author wnfbx
 */

import com.wheel.core.utils.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;

/**
 * <dt>Description:DroolsAutoConfiguration</dt>
 * <dd>drools 自动配置</dd>
 *
 * @author wnfbx
 * @version 1.0 <i>2021/7/26 10:43</i>
 * @since jdk1.7+
 */

@PropertySource(name = "drools", value = {"classpath:application-drools.properties"})
@EnableConfigurationProperties({DroolsAutoConfigurationProperties.class})
@ConditionalOnProperty(value = "w.drools.enable")
public class DroolsAutoConfiguration {

    private static final Logger log = LoggerFactory.getLogger(DroolsAutoConfiguration.class);

    public DroolsAutoConfiguration(DroolsAutoConfigurationProperties properties, DefaultListableBeanFactory factory) throws IOException {
        new DroolsBeanRegister(properties, factory);
        Log.registered(log);
    }

    @Bean
    public KieSessionTemplate kieSessionTemplate(ApplicationContext applicationContext) {
        return new KieSessionTemplate(applicationContext);
    }

}
